﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DBMigrator.Core.DbObjects.Data.Update;
using DBMigrator.Core.DbObjects.Data.Where;
using Rhino.Mocks;
using Xunit;

namespace DBMigrator.Core.Tests.DbObjects.Data
{
    public class UpdateTests
    {
        private readonly ISet set;
        private readonly IWhere where;

        public UpdateTests()
        {
            set = MockRepository.GenerateMock<ISet>();
            where = MockRepository.GenerateMock<IWhere>();
        }
        
        [Fact]
        public void SqlGenerationTypeShouldReturnIUpdate()
        {
            Assert.Equal(typeof(IUpdate), new Update(set, where, "TableName").SqlGenerationType);
        }

        [Fact]
        public void ConstructorShouldThrowIfSetIsNull()
        {
            Assert.Throws<ArgumentNullException>(() => new Update(null, where, "TableName"));
        }

        [Fact]
        public void ConstructorShouldSetSet()
        {
            Assert.Equal(set, new Update(set, where, "TableName").Set);
        }

        [Fact]
        public void ConstructorShouldThrowIfWhereIsNull()
        {
            Assert.Throws<ArgumentNullException>(() => new Update(set, null, "TableName"));
        }

        [Fact]
        public void ConstructorShouldSetWhere()
        {
            Assert.Equal(where, new Update(set, where, "TableName").Where);
        }

        [Fact]
        public void ConstructorShouldThrowIfTableNameIsNull()
        {
            Assert.Throws<ArgumentNullException>(() => new Update(set, where, null));
        }

        [Fact]
        public void ConstructorShouldThrowIfTableNameIsEmpty()
        {
            Assert.Throws<ArgumentNullException>(() => new Update(set, where, string.Empty));
        }

        [Fact]
        public void ConstructorShouldSetTableName()
        {
            var tableName = StringUtil.Random();
            Assert.Equal(tableName, new Update(set, where, tableName).TableName);
        }
    }
}
